package com.sylar.lelepub.adapter;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.sylar.lelepub.HandOrderInfoActivity;
import com.sylar.lelepub.R;

public class DetailPubAdapter extends BaseAdapter {
	// private List<DetailPage> detailPages;
	private Context mContext;
	private LayoutInflater mInflater;
	private List<String> detailPages;

	public DetailPubAdapter(Context context) {
		mContext = context;
		mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public void setListPageItems(List<String> detailPages) {
		this.detailPages = detailPages;
	}

	public int getCount() {
		if (detailPages != null)
			return detailPages.size();
		return 0;
	}

	// public DetailPage getItem(int position) {
	// if(detailPages!=null )
	// return detailPages.get(position);
	// return null;
	// }

	@Override
	public String getItem(int position) {
		if (detailPages != null)
			return detailPages.get(position);
		return null;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(final int position, View convertView, ViewGroup parent) {
		ImageHolder holder = null;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.detail_pub_list_item, null);
			holder = new ImageHolder();
			holder.tv_sleep_pub_bed_type = (TextView) convertView.findViewById(R.id.tv_sleep_pub_bed_type);
			holder.tv_sleep_pub_hasbreak = (TextView) convertView.findViewById(R.id.tv_sleep_pub_hasbreak);
			holder.tv_sleep_pub_bed_size = (TextView) convertView.findViewById(R.id.tv_sleep_pub_bed_size);
			holder.tv_sleep_pub_bed_hasnet = (TextView) convertView.findViewById(R.id.tv_sleep_pub_bed_hasnet);
			holder.tv_sleep_pub_bed_floor = (TextView) convertView.findViewById(R.id.tv_sleep_pub_bed_floor);
			holder.tv_sleep_pub_bed_price = (TextView) convertView.findViewById(R.id.tv_sleep_pub_bed_price);
			holder.tv_sleep_pub_bed_d_type = (TextView) convertView.findViewById(R.id.tv_sleep_pub_bed_d_type);
			holder.btn_sleep_pub_bed_remain = (Button) convertView.findViewById(R.id.btn_sleep_pub_bed_remain);
			convertView.setTag(holder);
		} else {
			holder = (ImageHolder) convertView.getTag();
		}
		
		if(position %2 ==0){
			holder.btn_sleep_pub_bed_remain.setBackgroundResource(R.drawable.pub_full_btn);
			holder.btn_sleep_pub_bed_remain.setText("满房");
		}else{
			holder.btn_sleep_pub_bed_remain.setBackgroundResource(R.drawable.global_orange_btn);
			holder.btn_sleep_pub_bed_remain.setText("预订");
			
		}
		holder.btn_sleep_pub_bed_remain.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(mContext,HandOrderInfoActivity.class);
				intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				mContext.startActivity(intent);
			}
		});
		return convertView;
	}

	private class ImageHolder {
		public TextView tv_sleep_pub_bed_type;
		public TextView tv_sleep_pub_hasbreak;
		public TextView tv_sleep_pub_bed_size;
		public TextView tv_sleep_pub_bed_hasnet;
		public TextView tv_sleep_pub_bed_floor;
		public TextView tv_sleep_pub_bed_price;
		public TextView tv_sleep_pub_bed_d_type;
		public Button btn_sleep_pub_bed_remain;
	}
}
